<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>SQL</title>
<script src="/webjars/jquery/2.1.1/jquery.min.js" type="application/javascript"></script>
<script src="/webjars/bootstrap/3.3.7/js/bootstrap.min.js" type="application/javascript"></script>
<link rel="stylesheet" href="/webjars/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="/webjars/bootstrap/3.3.7/css/bootstrap-theme.css">
</head>
<body>
<script>
    function init(param) {
        $.ajax({
            url:"data/queryCompany",
            dataType:"json",
            type:"POST",
            data:param,
            success:function (data) {
                var tbody = ""
                data.forEach(function (dt) {
                    tbody+="<tr><td>"+dt.user+"</td><td>"+dt.company+"</td></tr>"
                });
                $("#tb").html(tbody)
            }
        })
    }
    function add(param) {
        $.ajax({
            url:"data/add",
            dataType:"json",
            type:"POST",
            data:param,
            success:function (data) {
                //console.log(data);
                var tbody = ""
                data.forEach(function (dt) {
                    tbody+="<tr><td>"+dt.user+"</td><td>"+dt.company+"</td></tr>"
                });
                $("#tb").html(tbody)
            }
        })
    }
    window.onload = init(null);
</script>
<div class="container">
<div class="row">
<div class="col-lg-4">
    <div class="input-group">
        <span class="input-group-addon" id="basic-addon1">企业：</span>
        <input name="company" type="text" class="form-control" placeholder="企业名" aria-describedby="basic-addon1">
    </div>
</div>
<div class="col-lg-4">
    <div class="input-group">
        <span class="input-group-addon" id="basic-addon2">用户：</span>
        <input name="user" type="text" class="form-control" placeholder="用户名" aria-describedby="basic-addon1">
    </div>
</div>
    <div class="btn-default">
        <button type="button" onclick="init({'user':$('[name=user]').val(),'company':$('[name=company]').val()})" class="btn btn-default">提交</button>
        <button type="button" onclick="add({'user':$('[name=user]').val(),'company':$('[name=company]').val()})" class="btn btn-default">新增</button>
    </div>
</div>
<table class="table table-hover col-lg-6">
    <thead>
    <tr>
        <th>用户</th>
        <th>企业</th>
    </tr>
    </thead>
    <tbody id="tb"></tbody>
</table>
</div>
</body>
</html>